<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="inc/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <%@ include file="inc/meta.jsp" %>
    <meta name="description" content="">
    <meta name="author" content="">
    <title>企业广告主认证</title>
    <%@ include file="inc/css.jsp" %>
</head>
<body>

<div id="videos" class="wrapper">

    <%@ include file="inc/nav.jsp" %>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">基本信息</h1>
            </div>
        </div>

        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <input type="hidden" id="tempCheckStatus" value="${companyAuth.companyUser.checkStatus}"/>

                        <form id="infoForm" method="post" action="company/savePlus" class="form-horizontal" role="form" enctype="multipart/form-data">

                            <div class="form-group">
                                <label class="col-sm-2 control-label" style="font-size: 17px">企业信息</label>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">企业全称:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="companyName" name="companyName" maxlength="20" data-rule="required" placeholder="请输入企业全称" value="${companyAuth.companyName}"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">营业执照:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="licenseNum" name="licenseNum" maxlength="50" data-rule="required" placeholder="请输入营业执照" value="${companyAuth.licenseNum}"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">执照照片:</label>

                                <div class="col-sm-8" style="padding-top: 6.5px;">
                                    <input type="file" name="license_url" id="mainImage" style="display:none;"/>
                                    <a href="javascript:void(0);" onclick="_companyCheck.fn.AddImg()">
                                        <img id="mainPicture"
                                             <c:if test="${null != companyAuth && null != companyAuth.licenseUrl && '' != companyAuth.licenseUrl}">src="${companyAuth.licenseUrl}"</c:if>
                                             <c:if test="${null == companyAuth || null == companyAuth.licenseUrl || '' == companyAuth.licenseUrl}">src="static/images/add.jpg"</c:if>
                                             style="height: 200px; width: 200px; display: inline; margin-bottom: 5px;" border="1"/>
                                    </a>

                                    <input type="file" name="license_url2" id="mainImage2" style="display:none;"/>
                                    <a href="javascript:void(0);" onclick="_companyCheck.fn.AddImg2()">
                                        <img id="mainPicture2"
                                             <c:if test="${null != companyAuth && null != companyAuth.licenseUrl2 && '' != companyAuth.licenseUrl2}">src="${companyAuth.licenseUrl2}"</c:if>
                                             <c:if test="${null == companyAuth || null == companyAuth.licenseUrl2 || '' == companyAuth.licenseUrl2}">src="static/images/add.jpg"</c:if>
                                             style="height: 200px; width: 200px; display: inline; margin-bottom: 5px;" border="1"/>
                                    </a>

                                    <input type="file" name="license_url3" id="mainImage3" style="display:none;"/>
                                    <a href="javascript:void(0);" onclick="_companyCheck.fn.AddImg3()">
                                        <img id="mainPicture3"
                                             <c:if test="${null != companyAuth && null != companyAuth.licenseUrl3 && '' != companyAuth.licenseUrl3}">src="${companyAuth.licenseUrl3}"</c:if>
                                             <c:if test="${null == companyAuth || null == companyAuth.licenseUrl3 || '' == companyAuth.licenseUrl3}">src="static/images/add.jpg"</c:if>
                                             style="height: 200px; width: 200px; display: inline; margin-bottom: 5px;" border="1"/>
                                    </a>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label" style="font-size: 17px">负责人信息</label>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">负责人姓名:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="userName" name="userName" maxlength="20" data-rule="required" value="${companyAuth.userName}" placeholder="请输入手机号码"/>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号码:</label>

                                <div class="col-sm-4">
                                    <input type="text" class="form-control" id="mobile" name="mobile" maxlength="20" data-rule="required" value="${companyAuth.mobile}" placeholder="请输入手机号码"/>
                                </div>
                            </div>

                            <div class="form-group" id="failReasonDiv" style="display: none">
                                <label class="col-sm-2 control-label"></label>

                                <div class="col-sm-8" style="padding-top: 6.5px;">
                                    <c:if test="${null != companyAuth}">
                                        审核失败，原因：${companyAuth.companyUser.checkFailReason}
                                    </c:if>
                                </div>
                            </div>

                            <div class="form-group">
                                <div class="col-sm-12" style="text-align: center">
                                    <a href="javascript:void(0)" onclick="_companyCheck.fn.subInfo()" id="subButton" class="btn btn-success" role="button">提交审核</a>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!-- /.panel-body -->

                </div>
            </div>
        </div>

    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<%@ include file="inc/footer.jsp" %>

</body>

<script type="text/javascript">
    var _companyCheck = {
        fn: {
            init: function () {
                $("#mainImage").uploadPreview({
                    Img: "mainPicture",
                    Width: 200,
                    Height: 170
                });

                $("#mainImage2").uploadPreview({
                    Img: "mainPicture2",
                    Width: 200,
                    Height: 170
                });

                $("#mainImage3").uploadPreview({
                    Img: "mainPicture3",
                    Width: 200,
                    Height: 170
                });

                var checkStatus = $('#tempCheckStatus').val();
                if (null != checkStatus && checkStatus != '') {
                    if (checkStatus == 0) {
                        // 待审核
                        $('#subButton').text('审核中');
                        $('#subButton').attr('disabled', "true");
                        $('#subButton').removeClass().addClass('btn btn-warning');
                    } else {
                        // 审核不通过
                        $('#failReasonDiv').css('display', '');
                        $('#subButton').text('重新提交');
                    }
                }
            },
            subInfo: function () {
                var flag = true;
                var companyName = $('#companyName').val();
                var licenseNum = $('#licenseNum').val();
                var url = $('#mainPicture').prop('src');
                var userName = $('#userName').val();
                var mobile = $('#mobile').val();

                if (null == companyName || companyName == '') {
                    $leoman.notify("请输入企业全称", "error");
                    flag = false;
                    return;
                }

                if (null == licenseNum || licenseNum == '') {
                    $leoman.notify("请输入营业执照", "error");
                    flag = false;
                    return;
                }

                if (null == url || url == '' || url == _basePath + 'static/images/add.jpg' || url == 'static/images/add.jpg') {
                    $leoman.notify("第一张执照照片不能为空", "error");
                    flag = false;
                    return;
                }

                if (null == userName || userName == '') {
                    $leoman.notify("请输入负责人姓名", "error");
                    flag = false;
                    return;
                }

                if (null == mobile || mobile == '') {
                    $leoman.notify("请输入手机号码", "error");
                    flag = false;
                    return;
                }

                // 所有的验证通过后，执行新增操作
                if (flag) {
                    $('#infoReduceDialogModal').modal("show");

                    $("#infoForm").ajaxSubmit({
                        url: _basePath + "company/savePlus",
                        dataType: "json",
                        success: function (result) {
                            $('#infoReduceDialogModal').modal("hide");
                            if (result > 0) {
                                $leoman.notify("操作成功", "success");
                                $('#failReasonDiv').css('display', 'none');
                                $('#subButton').text('审核中');
                                $('#subButton').attr('disabled', "true");
                                $('#subButton').removeClass().addClass('btn btn-warning');
                            } else if (result == -1) {
                                window.location.href = 'company/login';
                            } else {
                                $leoman.notify("操作失败", "error");
                            }
                        }
                    });
                }
            },
            AddImg: function () {
                // a标签绑定onclick事件
                $('#mainImage').click();
            },
            AddImg2: function () {
                // a标签绑定onclick事件
                $('#mainImage2').click();
            },
            AddImg3: function () {
                // a标签绑定onclick事件
                $('#mainImage3').click();
            }
        }
    }

    $(document).ready(function () {
        _companyCheck.fn.init();
    });

</script>

</html>